

package com.sunny.core.service.impl;


import org.springframework.beans.factory.annotation.Autowired;

import com.sunny.core.service.IBaseService;

import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * Created by liuzh on 2014/12/11.
 */
public abstract class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    protected Mapper<T> mapper;

    public Mapper<T> getMapper() {
        return mapper;
    }

    public List<T> select(T entity) {
        return mapper.select(entity);
    }    
    
    public T selectByKey(Object key) {
        return mapper.selectByPrimaryKey(key);
    }

    public int save(T entity) {
        return mapper.insert(entity);
    }

    public int delete(Object key) {
        return mapper.deleteByPrimaryKey(key);
    }

    public int updateAll(T entity) {
        return mapper.updateByPrimaryKey(entity);
    }

    public int updateNotNull(T entity) {
        return mapper.updateByPrimaryKeySelective(entity);
    }

    public List<T> selectByExample(Object example) {
        return mapper.selectByExample(example);
    }
    
    public int updateByPrimaryKey(T entity) {
    	return mapper.updateByPrimaryKey(entity);
    }
    
    public int updateByPrimaryKeySelective(T entity) {
    	return mapper.updateByPrimaryKeySelective(entity);
    }
    
    public T selectByPrimaryKey(T entity) {
    	return mapper.selectByPrimaryKey(entity);
    }

    //TODO 其他...
}
